/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SearchView.java
 *
 * Created on 2011-mar-06, 12:18:18
 */

package imat;

import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author Andreas
 */
public class SearchView extends javax.swing.JPanel {

    private SearchPresenter searchPresenter;
    private String searchTerm;

    /** Creates new form SearchView */
    public SearchView() {
        initComponents();

        searchPresenter = new SearchPresenter(this);
    }

    public void search(String str) {
        searchPresenter.search(str);
        searchTerm = str;
    }

    public JPanel getProductsPanel() {
        return productsPanel;
    }

    public JLabel getTitle() {
        return title;
    }
    
    public JPanel getShowAllPanel() {
        return showAllPanel;
    }

    public JPanel getScrollPanel() {
        return scrollPanel;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        scrollPanel = new javax.swing.JPanel();
        title = new javax.swing.JLabel();
        productsPanel = new javax.swing.JPanel();
        showAllPanel = new javax.swing.JPanel();
        capLabel = new javax.swing.JLabel();
        showAllButton = new javax.swing.JButton();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(imat.IMatApp.class).getContext().getResourceMap(SearchView.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setName("jScrollPane1"); // NOI18N
        jScrollPane1.setPreferredSize(new java.awt.Dimension(540, 200));
        jScrollPane1.getVerticalScrollBar().setUnitIncrement(100);

        scrollPanel.setBackground(resourceMap.getColor("scrollPanel.background")); // NOI18N
        scrollPanel.setName("scrollPanel"); // NOI18N
        scrollPanel.setPreferredSize(new java.awt.Dimension(540, 200));

        title.setFont(resourceMap.getFont("title.font")); // NOI18N
        title.setText(resourceMap.getString("title.text")); // NOI18N
        title.setName("title"); // NOI18N

        productsPanel.setBackground(resourceMap.getColor("productsPanel.background")); // NOI18N
        productsPanel.setMinimumSize(new java.awt.Dimension(0, 44));
        productsPanel.setName("productsPanel"); // NOI18N
        productsPanel.setPreferredSize(new java.awt.Dimension(30, 30));
        productsPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 15, 15));

        javax.swing.GroupLayout scrollPanelLayout = new javax.swing.GroupLayout(scrollPanel);
        scrollPanel.setLayout(scrollPanelLayout);
        scrollPanelLayout.setHorizontalGroup(
            scrollPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(scrollPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(scrollPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(productsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 568, Short.MAX_VALUE)
                    .addGroup(scrollPanelLayout.createSequentialGroup()
                        .addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, 518, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(50, Short.MAX_VALUE))))
        );
        scrollPanelLayout.setVerticalGroup(
            scrollPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(scrollPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(title)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(productsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 391, Short.MAX_VALUE)
                .addContainerGap())
        );

        jScrollPane1.setViewportView(scrollPanel);

        showAllPanel.setBackground(resourceMap.getColor("showAllPanel.background")); // NOI18N
        showAllPanel.setName("showAllPanel"); // NOI18N

        capLabel.setText(resourceMap.getString("capLabel.text")); // NOI18N
        capLabel.setName("capLabel"); // NOI18N
        showAllPanel.add(capLabel);

        showAllButton.setText(resourceMap.getString("showAllButton.text")); // NOI18N
        showAllButton.setName("showAllButton"); // NOI18N
        showAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showAllButtonActionPerformed(evt);
            }
        });
        showAllPanel.add(showAllButton);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(showAllPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 558, Short.MAX_VALUE)
                .addGap(12, 12, 12))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 582, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 445, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(showAllPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void showAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showAllButtonActionPerformed
        searchPresenter.search(searchTerm, true);
    }//GEN-LAST:event_showAllButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel capLabel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel productsPanel;
    private javax.swing.JPanel scrollPanel;
    private javax.swing.JButton showAllButton;
    private javax.swing.JPanel showAllPanel;
    private javax.swing.JLabel title;
    // End of variables declaration//GEN-END:variables

   

}
